home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / Simple Slideshow / clut_fade 1.2 ƒ / Shell.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-08  |  4.9 KB  |  199 lines  |  [TEXT/KAHL]

  1. /********************************************************************************
  2.  
  3.      PROJECT:    clut_fade.π
  4.      
  5.      FILE:        shell.c
  6.      
  7.      PURPOSE:    'clut' fading functions
  8.      
  9.      STATUS:        Public Domain Demo.
  10.  
  11.  ********************************************************************************/
  12.  
  13. //=================================    INCLUDES ====================================
  14.  
  15. #include "shell.h"
  16. #include "fade.h"
  17.  
  18. //=================================    FUNCTIONS ===================================
  19.  
  20. void init_toolbox(void);
  21. void test_window(void);
  22.  
  23.  
  24. /*********************************** main ***************************************/
  25. extern
  26. void main(void)
  27. {
  28.     init_toolbox();
  29.     test_window();    
  30. }
  31. /*** main ***/
  32.  
  33. /********************************** init_toolbox ********************************/
  34. static
  35. void init_toolbox(void)
  36. {
  37.     MaxApplZone();
  38.     MoreMasters();
  39.     InitGraf(&thePort);
  40.     InitFonts();
  41.     InitWindows();
  42.     InitMenus();
  43.     TEInit();
  44.     InitDialogs(nil);
  45.     InitCursor();
  46.     FlushEvents(everyEvent, 0);
  47. }
  48. /*** init_toolbox ***/
  49.  
  50. /********************************** test_window *********************************/
  51. static
  52. void test_window(void)
  53. {
  54.     DialogPtr    d;
  55.     GrafPtr        g;
  56.     short        hit;
  57.     GDHandle    hGD;
  58.     CTabHandle    hCTab;
  59.     long ticks;
  60.     
  61.     if (d = GetNewDialog(128, nil, (WindowPtr) -1L))
  62.     {
  63.         GetPort(&g);
  64.         SetPort(d);
  65.         ShowWindow(d);
  66.         
  67.         do
  68.         {
  69.             ModalDialog(nil, &hit);
  70.             switch (hit)
  71.             {
  72.                 // fade all monitors to black
  73.                 case    2:
  74.                     // fade out
  75.                     fade_to_black(128, fadeAll, true);
  76.                     // wait a few seconds
  77.                     Delay (120L, &ticks);
  78.                     // fade in
  79.                     fade_to_black(128, fadeAll, false);
  80.                     break;
  81.  
  82.                 // fade main monitor to black
  83.                 case    3:
  84.                     // fade out
  85.                     fade_to_black(128, fadeMainOnly, true);
  86.                     // wait a few seconds
  87.                     Delay (120L, &ticks);
  88.                     // fade in
  89.                     fade_to_black(128, fadeMainOnly, false);
  90.                     break;
  91.                     
  92.                 // fade all monitors except main monitor to black
  93.                 case    4:
  94.                     // fade out
  95.                     fade_to_black(128, fadeAllButMain, true);
  96.                     // wait a few seconds
  97.                     Delay (120L, &ticks);
  98.                     // fade in
  99.                     fade_to_black(128, fadeAllButMain, false);
  100.                     break;
  101.                     
  102.                 // fade main monitor to red
  103.                 case    5:
  104.                     {
  105.                     CTabHandle    origColors;
  106.                     GDHandle    mainDevice = GetMainDevice();
  107.                     RGBColor    aColor;
  108.                         
  109.                         // make a copy of the color table so we can restore it later
  110.                         copy_gdevice_clut(mainDevice,&origColors);
  111.                         
  112.                         // fade to a color
  113.                         aColor.red = 65535;
  114.                         aColor.green = 0;
  115.                         aColor.blue = 0;
  116.                         fade_to_color(128,&aColor,mainDevice);
  117.                         
  118.                         // wait a few seconds
  119.                         Delay (120L, &ticks);
  120.                         
  121.                         // fade back to original color table
  122.                         fade_to_clut(128,origColors,mainDevice);
  123.                         
  124.                         // dispose the copy we made
  125.                         DisposeHandle((Handle)origColors);
  126.                     }
  127.                     break;
  128.  
  129.                 // fade main monitor through rainbow
  130.                 case    6:
  131.                     {
  132.                     CTabHandle    origColors;
  133.                     CTabHandle    newColors;
  134.                     short        x;
  135.                     GDHandle    mainDevice = GetMainDevice();
  136.                         
  137.                         // make a copy of the color table so we can restore it later
  138.                         copy_gdevice_clut(mainDevice,&origColors);
  139.                         
  140.                         for (x = 128; x < 135; x++)
  141.                         {
  142.                             // get a custom color table (red or blue)
  143.                             newColors = GetCTable(x);
  144.                             // limit it to current depth
  145.                             (**newColors).ctSize = (**origColors).ctSize;
  146.                             SetHandleSize((Handle)(**newColors).ctTable, sizeof(short) + (sizeof(RGBColor) * ((**newColors).ctSize+1)));
  147.                             // fade to the custow color table
  148.                             fade_to_clut(40,newColors,mainDevice);
  149.                         ReleaseResource((Handle)newColors);
  150.                         }
  151.  
  152.                         // fade back to original color table
  153.                         fade_to_clut(40,origColors,mainDevice);
  154.                         // dispose the copy we made
  155.                         DisposeHandle((Handle)origColors);
  156.                     }
  157.                     break;
  158.                     
  159.                 // fade to inverted clut
  160.                 case    7:
  161.                     {
  162.                     CTabHandle    origColors;
  163.                     CTabHandle    newColors;
  164.                     RGBColor    aColor;
  165.                     short        x;
  166.                     GDHandle    mainDevice = GetMainDevice();
  167.                         
  168.                         // make a copy of the color table so we can restore it later
  169.                         copy_gdevice_clut(mainDevice,&origColors);
  170.                         // make a copy of the color table so we manipulate it
  171.                         copy_gdevice_clut(mainDevice,&newColors);
  172.                         // reverse order of colors for a fun effect
  173.                         for (x = 0; x < (((**newColors).ctSize+1)/2); x++)
  174.                         {
  175.                             aColor = (**newColors).ctTable[x].rgb;
  176.                             (**newColors).ctTable[x].rgb = (**newColors).ctTable[(**newColors).ctSize - x].rgb;
  177.                             (**newColors).ctTable[(**newColors).ctSize - x].rgb = aColor;
  178.                         }
  179.                         // fade to it
  180.                         fade_to_clut(128,newColors,mainDevice);
  181.                         // wait a few seconds
  182.                         Delay (120L, &ticks);
  183.                         // fade back to original color table
  184.                         fade_to_clut(128,origColors,mainDevice);
  185.                         // dispose the copy we made
  186.                         DisposeHandle((Handle)origColors);
  187.                     }
  188.                     break;
  189.             }
  190.         }
  191.         while (hit != OK);
  192.         
  193.         SetPort(g);
  194.         DisposDialog(d);
  195.     }
  196. }
  197. /*** test_window ***/
  198.  
  199. //===================================== EOF =====================================